from http_evented import http_evented
import urllib

class node_notifier(http_evented):
    """
    This class is responsible for notifying individual pymq nodes
    in a pymq cluster as to when they need to be activated. It will
    be used by the master node in the cluster. This class also aids
    querying the node for the list of queues it is currently handling
    """
    def __init__(self, host_and_port, onConnected=None,
                 onClose=None, onException=None):
        http_evented.__init__(self, host_and_port, onConnected,
                              onClose, onException)

    def activate_node(self, connectionString, onNodeActivated=None):
        url = "/_ah/command/node/activate/?" + \
            urllib.urlencode({ "connectionString": connectionString })
        self.make_HTTP_request("GET", url=url, body="", headers={},
                               callback=onNodeActivated)

    def get_queue_list(self, onGotQueueList=None):
        url = "/_ah/command/all/queueList/"
        self.make_HTTP_request("GET", url=url, body="", headers={},
                               callback=onGotQueueList)
